package com.jinlejia.feedback.idea.ui;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jinlejia.feedback.R;

/**
 * @author SongJiaTai
 * @description:提示是否删除Dialog
 * @date :2019/7/2 11:30
 */
public class FbDeleteDialog extends AlertDialog implements View.OnClickListener{
    private String mTitle,mContent;
    protected FbDeleteDialog(Context context,String tile,String content) {
        super(context);
        this.mTitle = tile;
        this.mContent = content;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = this.getWindow();
        // *** 主要就是在这里实现这种效果的.
        // 设置窗口的内容页面,shrew_exit_dialog.xml文件中定义view内容
        window.setContentView(R.layout.fb_dialog_delete);
        window.setGravity(Gravity.CENTER);
        window.setBackgroundDrawable(new ColorDrawable());
        window.setLayout(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        //取消
        TextView cancle = (TextView) window.findViewById(R.id.id_cancel);
        //确定
        TextView confirm = (TextView) window.findViewById(R.id.id_confirm);

        //title
        TextView title = (TextView) window.findViewById(R.id.title);
        //content
        TextView content = (TextView) window.findViewById(R.id.content);

        title.setText( mTitle);
        content.setText( mContent );

        cancle.setOnClickListener(this);
        confirm.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        int i = v.getId();
        if (i == R.id.id_cancel) {
            dismiss();

        } else if (i == R.id.id_confirm) {//确定
            dismiss();
            if (null != confirmListener)
                confirmListener.confirm();

        } else {
        }
    }




    public interface OnConfirmListener {
        public void confirm();
    }

    private OnConfirmListener confirmListener;

    public void setConfirmListener(OnConfirmListener listener) {
        this.confirmListener = listener;
    }
}
